package com.ewe.retrofit;

import cn.hutool.core.codec.Base64;
import cn.hutool.http.HttpRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author Levin
 */
@Component
public class EbayClient {

    private static final String AUTHORIZATION = "Authorization";
    private static final String AUTHORIZATION_VALUE = "Basic %s";
    private static final String CONTENT_TYPE = "Content-Type";
    private static final String CONTENT_TYPE_VALUE = "application/x-www-form-urlencoded";

    @Value("${ebay.token.url}")
    private String ebayTokenUrl;

    public String getToken() {
        String encode = "";
        return HttpRequest.post(ebayTokenUrl)
                .header(CONTENT_TYPE, CONTENT_TYPE_VALUE)
                .header(AUTHORIZATION, String.format(AUTHORIZATION_VALUE, encode))
                .form("grant_type", "client_credentials")
                .form("scope", "https://api.ebay.com/oauth/api_scope").execute().body();
    }


}
